package com.zjitc.controller;

import com.zjitc.model.Product;
import com.zjitc.service.ProductService;
import com.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.InternalResourceView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Administrator 主页展示最热商品和最新商品
 */
@Controller
public class IndexControl {

    @Autowired
    private ProductService service;

    @RequestMapping(value = "/index")
    public ModelAndView index(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        mv.setView(new InternalResourceView("/jsp/index.jsp"));
        List<Product> hot = service.findHot();
        List<Product> nest = service.findNest();
        mv.addObject("hots", hot);
        mv.addObject("nests", nest);
        String address = (String) request.getAttribute("address");
        System.out.println(address);
        return mv;
    }
}
